/** 
 * CanvasPopupMenu.java
 * @author Lex
 * 2007-8-26 ����03:46:19
 */
package fun.ui.canvas.control;

import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;

import fun.ui.FunMainFrame;
import fun.ui.canvas.CanvasPane;
import fun.ui.frames.FunctionFrame;

public class PopupMenu extends JPopupMenu {
	private JMenuItem colorsMenuItem = null;
	private JMenuItem rangesMenuItem = null;
	private JMenuItem saveMenuItem = null;
	// ====================================
	private FunMainFrame mainframe = null;
	private FunctionFrame parent = null;
	private CanvasPane canvas = null;

	public PopupMenu(FunMainFrame mainframe, FunctionFrame parent, CanvasPane canvas) {
		super();
		this.mainframe = mainframe;
		this.parent = parent;
		this.canvas = canvas;
		initialize();
	}

	private void initialize() {
		this.add(getColorsMenuItem());
		this.add(getRangesMenuItem());
		this.addSeparator();
		this.add(getSaveMenuItem());
	}

	private JMenuItem getColorsMenuItem() {
		if (colorsMenuItem == null) {
			colorsMenuItem = new JMenuItem();
			colorsMenuItem.setAction(new ColorsAction(mainframe, parent, canvas));
		}
		return colorsMenuItem;
	}

	private JMenuItem getRangesMenuItem() {
		if (null == this.rangesMenuItem) {
			this.rangesMenuItem = new JMenuItem();
			this.rangesMenuItem.setAction(new RangesAction(mainframe, parent, canvas));
		}
		return this.rangesMenuItem;
	}

	private JMenuItem getSaveMenuItem() {
		if (saveMenuItem == null) {
			saveMenuItem = new JMenuItem();
			saveMenuItem.setAction(new SaveAction(mainframe, parent, canvas));
		}
		return saveMenuItem;
	}
}
